package com.osce.face.controller;

import com.csce.domain.entity.face.FaceWhiteList;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.face.IFaceWhiteListService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 人脸白名单Controller
 *
 * @author zzx
 * @since 2023-11-21
 */
@RestController
@RequestMapping("/face/face_white")
public class FaceWhiteListController extends BaseController {

    @Resource
    private IFaceWhiteListService faceWhiteListService;

    /**
     * 查询人脸白名单列表
     */
    @PreAuthorize("@ss.hasPermi('face:face_white:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaceWhiteList faceWhiteList) {
        startPage();
        List<FaceWhiteList> list = faceWhiteListService.selectFaceWhiteListList(faceWhiteList);
        return getDataTable(list);
    }

    /**
     * 导出人脸白名单列表
     */
    @PreAuthorize("@ss.hasPermi('face:face_white:export')")
    @Log(title = "人脸白名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaceWhiteList faceWhiteList) {
        List<FaceWhiteList> list = faceWhiteListService.selectFaceWhiteListList(faceWhiteList);
        ExcelUtil<FaceWhiteList> util = new ExcelUtil<FaceWhiteList>(FaceWhiteList.class);
        util.exportExcel(response, list, "人脸白名单数据");
    }

    /**
     * 获取人脸白名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('face:face_white:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(faceWhiteListService.selectFaceWhiteListById(id));
    }

    /**
     * 新增人脸白名单
     */
    @PreAuthorize("@ss.hasPermi('face:face_white:add')")
    @Log(title = "人脸白名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaceWhiteList faceWhiteList) {
        return toAjax(faceWhiteListService.insertFaceWhiteList(faceWhiteList));
    }

    /**
     * 批量新增人脸白名单
     */
    @PreAuthorize("@ss.hasPermi('face:face_white:add')")
    @Log(title = "人脸白名单", businessType = BusinessType.INSERT)
    @PostMapping("/more")
    public AjaxResult addMore(@RequestBody FaceWhiteList faceWhiteList) {
        return toAjax(faceWhiteListService.insertMoreFaceWhiteList(faceWhiteList));
    }

    /**
     * 修改人脸白名单
     */
    @PreAuthorize("@ss.hasPermi('face:face_white:edit')")
    @Log(title = "人脸白名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaceWhiteList faceWhiteList) {
        return toAjax(faceWhiteListService.updateFaceWhiteList(faceWhiteList));
    }

    /**
     * 删除人脸白名单
     */
    @PreAuthorize("@ss.hasPermi('face:face_white:remove')")
    @Log(title = "人脸白名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(faceWhiteListService.deleteFaceWhiteListByIds(ids));
    }
}
